//
//  SearchStarViewCell.m
//  WULIHH
//
//  Created by Gamefire on 16/4/14.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "SearchStarViewCell.h"
#import "Header.h"
#import "UIImageView+AFNetworking.h"

@interface SearchStarViewCell()

@property (nonatomic,strong)UIImageView *topImageView;
@property (nonatomic,strong)UILabel *namelabel;
@property (nonatomic,strong)UIButton *faonceBtn;

@property (nonatomic, assign) NSInteger rowInt;
@property (nonatomic, assign) NSInteger sectionInt;
@property (nonatomic, assign) int starInt;
@property (nonatomic, assign) int ISFlowInt;


@end
@implementation SearchStarViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        _topImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9, 9, 36, 36)];
        [self addSubview:_topImageView];
        
        _namelabel = [[UILabel alloc] initWithFrame:CGRectMake(53, 17, 200, 16)];
        [self addSubview:_namelabel];
        
        _faonceBtn = [[UIButton alloc] initWithFrame:CGRectMake(WithView - 82, 13, 59, 24)];
//        [_faonceBtn addTarget:self action:@selector(guanzhuStar:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_faonceBtn];
        
        UIView *lineview = [[UIView alloc] initWithFrame:CGRectMake(0, 52.5, WithView, 0.5f)];
        [lineview setBackgroundColor:[UIColor grayColor]];
        [self addSubview:lineview];
    }
    return self;
}



- (void)layoutSubviews{
    [super layoutSubviews];
    [_topImageView setBackgroundColor:[UIColor grayColor]];
    [_topImageView.layer setCornerRadius:18.0];
    [_topImageView.layer setMasksToBounds:YES];
    
//    [_namelabel setText:@"吴亦凡"];
//    [_namelabel setBackgroundColor:[UIColor blueColor]];
    [_namelabel setFont:[UIFont systemFontOfSize:16.0]];
    [_namelabel setTextAlignment:NSTextAlignmentCenter];
    [_namelabel setTextColor:[UIColor blackColor]];
    
    [_faonceBtn.titleLabel setFont:[UIFont systemFontOfSize:15]];
    [_faonceBtn.layer setCornerRadius:10.0];
}



- (void)setModelwithName:(NSString *)name withImage:(NSString *)imageIcon buttonWithTag:(NSInteger)tag withFlow:(int)flow withSectionInt:(NSInteger)sectionInt withStarID:(int)starIDInt
{
    [_namelabel setText:name];
    [_faonceBtn setTag:tag];
    _sectionInt = sectionInt;
    _starInt = starIDInt;
    _ISFlowInt = flow;
    
    
    
    [_topImageView setImageWithURL:[NSURL URLWithString:imageIcon]];
    [_faonceBtn addTarget:self action:@selector(yishuGuanzhu:) forControlEvents:UIControlEventTouchUpInside];
//    if ([array count] == 0)
//    {
        if (flow == 1)  //已经关注
        {
            [_faonceBtn setBackgroundColor:uicolor(192, 192, 192)];
            [_faonceBtn setTitle:@"已关注" forState:UIControlStateNormal];
            
        }
        else    //没有关注
        {
            [_faonceBtn setBackgroundColor:uicolor(226, 189, 45)];
            [_faonceBtn setTitle:@"关注" forState:UIControlStateNormal];
//            [_faonceBtn addTarget:self action:@selector(guanzhuStar:) forControlEvents:UIControlEventTouchUpInside];
        }
    
    
    [_faonceBtn addTarget:self action:@selector(yishuGuanzhu:) forControlEvents:UIControlEventTouchUpInside];
}




- (void)guanzhuStar:(UIButton *)sender
{
    if (_MSearchStarViewCellDelegate && [_MSearchStarViewCellDelegate respondsToSelector:@selector(pressGuanzhuWitghID:withTag: withSection:)])
    {
        [_MSearchStarViewCellDelegate pressGuanzhuWitghID:[NSString stringWithFormat:@"%d", _starInt] withTag:sender.tag withSection:_sectionInt];
    }
}


- (void)yishuGuanzhu:(UIButton *)sender
{
    
    if (_ISFlowInt == 1)
    {
        if (_MSearchStarViewCellDelegate && [_MSearchStarViewCellDelegate respondsToSelector:@selector(pressDeleteGuanzhu:withTag:withSection:)])
        {
            [_MSearchStarViewCellDelegate pressDeleteGuanzhu:[NSString stringWithFormat:@"%d", _starInt] withTag:sender.tag withSection:_sectionInt];
        }

    }
    else
    {
        if (_MSearchStarViewCellDelegate && [_MSearchStarViewCellDelegate respondsToSelector:@selector(pressGuanzhuWitghID:withTag: withSection:)])
        {
            [_MSearchStarViewCellDelegate pressGuanzhuWitghID:[NSString stringWithFormat:@"%d", _starInt] withTag:sender.tag withSection:_sectionInt];
            
        }

    }
    

}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
